<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html  xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>学校信息配置</title>
	<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
	<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
	<script type="text/javascript">
	/*
	定义全局变量oldCode ， 表示被修改的出单机构
	*/
	var oldCode = "";
	
	$(document).ready(function() {
		querySchoolConfig(1);
	});
	
	
	//为查询学校配置信息 拼接参数
	function querySchoolConfig(pageIndex){
		var dptCode = $.trim($('#dptCode').val());
		var schoolDesc = $.trim($('#schoolDesc').val());
		loadSchoolConfig({current:pageIndex,size:10,code:dptCode,codeDesc:schoolDesc});
	}
	
	//加载学校配置信息
	function loadSchoolConfig(param){
		$.openLoading();
		$.ajax({
				url : "<%=path%>/schoolConfiger/querySchoolConfig?"+new Date().getTime(),
				type : 'POST',
				async : true,
				dataType:'json',
				data:param,
				success : function(page) {
					$.closeLoading();
					if($.validate(page))return;
					var firstbutton ="<input class='input_fxk' name='radioSchoolConfig' type='radio' value='#'>";
					var lastbutton = "<a href='javascript:void(0)' onClick='editSchoolConfig(this);return false'>编辑</a>&nbsp;<a href='javascript:void(0)' onClick='delDict(this);return false'>删除</a>";
					var tableContent = creatTable1("oldcode,codedesc,codename,othercode,othercode2,insertdate,code@TDH",page,firstbutton,lastbutton);
					
					var tableObj = $("#schoolConfigTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					var strPage = creatChannelPage(param.current,10,page.maxPage,"100");
					var pageDIV = $("#schoolConfigPageDiv");
					pageDIV[0].innerHTML="";
					
					pageDIV.append(strPage);
					
					bindradio();//点击单选按钮，该行高亮显示
				}
			});
	}
	
	//绑定单选按钮事件，选中某个单选按钮，该按钮所在行高亮显示
	function bindradio(){
		$("input[name='radioSchoolConfig']").click(function(){
			$("input[name='radioSchoolConfig']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
       	});
		$("input[name='radioSchoolConfig']").click(function(){
			$("input[name='radioSchoolConfig']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
       	});
	}
	
	/* 删除条目 */
	function delDict(obj){
		//确定被编辑的对象行
		var editTr = $(obj).parent('td').parent('tr')[0];
		/* 
		code 与 codeType构成联合主键
		*/
		var codeType = 'school_config';
		var code = editTr.childNodes[7].innerHTML;
		//弹出确认窗口
		 $.dialog({
				type: "warn",
				content: "是否确认删除此条学校配置信息？",
				onOk: function() {
					delSchoolConfig({codeType:codeType,code:code});
				}
			});
		
		
	}
	function delSchoolConfig(param){
		
		$.openLoading();
		$.ajax({
			url : "schoolConfiger/delSchoolConfig",
			type : 'POST',
			async : true,
			dataType:'json',
			data:param,
			success : function(obj) {	
				$.closeLoading();
				//对返回信息进行校验 ， 若出错直接报错
				if($.validate(obj))
					return;
				querySchoolConfig(1);
			}
		});
		
	}
	//编辑,跳转至 编辑 页面
	/* 打开编辑窗体 */
	function editSchoolConfig(obj){
		//确定被编辑的对象行
		var editTr = $(obj).parent('td').parent('tr')[0];
		//获取改行数据并回写至页面上
		var code = editTr.childNodes[1].innerHTML;
		var codeDesc = editTr.childNodes[2].innerHTML;
		var codeName = editTr.childNodes[3].innerHTML;
		var otherCode = editTr.childNodes[4].innerHTML;
		var otherCode2 = editTr.childNodes[5].innerHTML;
		oldCode = editTr.childNodes[7].innerHTML;
		
		$("#eOldCode").val(oldCode);
		$("#eCode").val(code);
		$("#eCodeName").val(codeName);
		$("#eCodeDesc").val(codeDesc);
		$("#eOtherCode").val(otherCode);
		$("#eOtherCode2").val(otherCode2);
		//显示编辑窗体
		$("#editDictDiv").OpenDiv();
	}
	
	/* 单击保存 ，将该条字典信息更新或新增 */
	function saveEditDict(){
		var editDIV = $("#editDictDiv");
		//取得编辑窗体的内容
		var oldCode = $("#eOldCode").val();
		var codeName = $("#eCodeName").val();
		var codeDesc = $("#eCodeDesc").val();
		var otherCode = $("#eOtherCode").val();
		var otherCode2 = $("#eOtherCode2").val();
		var codeStatus = '1';
		if(codeDesc==""){
	    	$.message("error","请输入学校描述");
	    	$prodType.focus();
	    	return false;
	    }
		if(codeName==""){
	    	$.message("error","请输入学校名称");
	    	$prodType.focus();
	    	return false;
	    }
		if(otherCode==""){
	    	$.message("error","请输入年级");
	    	$prodType.focus();
	    	return false;
	    }
		if(otherCode2==""){
	    	$.message("error","请输入班级");
	    	$prodType.focus();
	    	return false;
	    }
		
		updateDictInfo({code:oldCode,schoolName:codeName,schoolDesc:codeDesc,gradeName:otherCode,className:otherCode2});
		
	}
	
	//编辑字典ajax
	function updateDictInfo(param){
		$.openLoading();
		$.ajax({
			url : "schoolConfiger/updateSchoolConfig",
			type : 'POST',
			async : true,
			dataType:'json',
			data:param,
			success : function(obj) {	
				$.closeLoading();
				//对返回信息进行校验 ， 若出错直接报错
				if($.validate(obj))
					return;
				querySchoolConfig(1);
				closeCurrentDIV('editDictDiv');
			}
		});
	}
	
	//------------------------------------------ 出单机构 开始----------------------------------------------
	//打开出单机构窗口
	function openDeptDiv(pageIndex,obj){
		
		$('#deptCode').val('');
		$('#deptCname').val('');
		$("#"+obj.id).blur();
		queryCoreDept(pageIndex);
	}

	//查询出单机构
	function queryCoreDept(pageIndex){
		var size = 8;
		var deptCode = $.trim($('#deptCode').val());
		var deptCname = $.trim($('#deptCname').val());
		var parentDeptCode =  '00';
		
		$.openLoading();
		$.ajax({
			url : "<%=path%>/nocarPolicyList/queryDeptByDeptAndParentDeptCode",
			type : 'POST',
			async : true,
			data:{
				size:size,
				pageIndex:pageIndex,
				deptCode:deptCode,
				deptCname:deptCname,
				parentDeptCode:parentDeptCode
			},
			dataType:'json',
			success:function(page){
				$.closeLoading();
				if($.validate(page))return;
				
				var radioObj ="<input class='input_fxk' name='deptradio' type='radio' value=''>";
				var fieldNames = "deptCode,deptCNname";
				var tableContent = creatTable1(fieldNames,page,radioObj);
				var tableObj = $("#deptTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage3(pageIndex,6,page.maxPage,"18");
				var pageDIV = $("#deptPageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				
				$("#deptDiv").OpenDiv();
				
				bindradio();
			}
		});
	}
	
	//点击“确定” ，选择 出单机构
	function chooseDept(){
		var selectedDept= $("input[name='deptradio']:checked");
		if(selectedDept.length==0){
			$.message("error", "请选择一个出单机构");
			return;
		}
		var deptCode = selectedDept.parent().parent().children(" td:eq(1)").html();
		$('#dptCode').val(deptCode);
		
		closeCurrentDIV('deptDiv');
	}
	
	//------------------------------------------ 出单机构 结束----------------------------------------------

	
	//模板下载
	function downloadSchoolConfig(){
			var dptCde= $("#dptCode").val();
			var schoolDesc= $("#schoolDesc").val();
			window.open("<%=basePath%>"+"schoolConfiger/demandExportExcel?code="+dptCde+"&codeDesc="+schoolDesc);
	}
	
	//导入
	function upLoadExcelForDemand(param){
		$.openLoading();
		var fileNameStr = $('#fileToUpload').val();
		fileNameStr = fileNameStr+"";
		var lastDotIndex = fileNameStr.lastIndexOf(".");
		if(lastDotIndex==-1){
			$.closeLoading();
			$.message("error","请选择扩展名为 .xls 的文件上传");
			return;
		}else{
			var extName = fileNameStr.substring(lastDotIndex+1, fileNameStr.length);
			if(extName.toLowerCase() != "xls"){
				$.closeLoading();
				$.message("error","请选择扩展名为 .xls 的文件上传");
				return;
			}
		}
		$.ajaxFileUpload({
	        url:'<%=path%>/schoolConfiger/schoolConfigExcelImport',
	        fileElementId :'fileToUpload',//file控件id
	        dataType: 'json',
	        success : function (data){
	        	$("#fileToUpload").val("")
	        	$.closeLoading();
	        	if(data.result=="error"||data.result=="fail"){
	        		$.dialog({
		    			width: 358,
		    			top:40,
		    			modal:true,
		    			Close:true,
		    			cancel:null,
		    			content: data.message
		    		});
		        	return;
	        	}
	        	querySchoolConfig(1);
	        	if($.validate(data)) return;
	        }
		});
	}
	
	
	//统一 关闭窗口(传入要关闭DIV的id)
	function closeCurrentDIV(obj){
			$("#"+obj).CloseDiv();	
	}
	</script>
</head>
<body >
	<div class="current">
           <table class="current_table_1">
              <tbody>
                <tr class="f2">
                  <td>
                    <img src="./images/current_1.jpg">
                  </td>
                  <td class="current_table_1_td">
                    <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                      <span style=" color:#136bab; ">界面出单管理
                      <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>学校信息配置
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody>
         </table>
      </div>
      
		<table class="table_02" id="table">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td width="40%" height="30">出单机构：
								&nbsp;&nbsp;<input id="dptCode" name="dptCode" type="text" readonly="readonly" style=" background-color: #ccc;" class="input_text">&nbsp;&nbsp;<input type="button"  class="input_button_5" id="searchDeptBtn" value="请选择" onClick="openDeptDiv(1,this)"/>
							</td>
							<td width="40%" height="30">学校描述：
								&nbsp;&nbsp;<input name="schoolDesc" id="schoolDesc" class="input_text" style="width:130px;" size="25"/>
							</td>
							<td>
								<input type="button"  class="input_button_1"  value="查询"    onClick="querySchoolConfig(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tbody>
				<tr>
					<td>
						<div>
							<div align="left" style="margin:15px">
								<input type="button"  class="input_button_2"  value="清单导出"    onClick="downloadSchoolConfig()"/>
								<input type="button"  class="input_button_2"  value="清单导入"    onclick="$('#fileToUpload').click()"/>
								<input  id="fileToUpload" name="myfiles" type='file' style='display: none;' onchange="upLoadExcelForDemand(this.value)"/>
							</div>
							<table class="table_02" id="schoolConfigTable">
						  		<thead>
					               <tr>
					               	  <th style="width:4%" nowrap="nowrap">选择</th>
					                  <th style="width:8%" nowrap="nowrap">出单机构代码</th>
					                  <th style="width:10%" nowrap="nowrap">学校描述</th>
					                  <th style="width:10%" nowrap="nowrap">学校名称</th>
					                  <th style="width:6%" nowrap="nowrap">年级/学院名称/教学系</th>
					                  <th style="width:8%" nowrap="nowrap">班级/专业名称</th>
					                  <th style="width:12%" nowrap="nowrap">定义时间</th>
					                  <th style="width:10%" nowrap="nowrap">操作</th>
					                  <th style="display: none">code</th>
					              	</tr>
					              </thead>
				              <tbody>
							  </tbody>
				            </table>
				            
        <!-- 编辑DIV 默认隐藏  -->
		
		<div id="editDictDiv"  style="display:none;overflow-y:auto; width:60%">
			<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="/manager/images/closedown.gif" alt="关闭"  onclick="closeEditDictDiv()"/></td>
						</tr>
					</table>
			</div>
			<!-- 修改id 名 -->
			<table class="table_02" id="addtempletTable" align="center">
				<tbody>
					<tr>
						<td>
							<table id="coverageTable"  class="content_table_1" style="height:120px;">
								
								<tbody>
									<tr style="display: none;">
					                  <td>
					                  	<input type="text" id="eCode" class="input_text" style="width: 250px">
					                  	<input type="text" id="eOldCode" class="input_text" style="width: 250px">
					                  	<input type="text" id="eOldClassName" class="input_text" style="width: 250px">
				                  	  </td>
					                </tr>
					                <tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">学校名称：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eCodeName" class="input_text" style="width: 250px"><span class="red">*</span></td>
					                </tr>
					                 <tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">学校描述：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eCodeDesc" class="input_text" style="width: 250px"><span class="red">*</span></td>
					                </tr>
					                <tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">年级：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eOtherCode" class="input_text" style="width: 250px"><span class="red">*</span></td>
					                </tr>
					                <tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">班级：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eOtherCode2" class="input_text" style="width: 250px"><span class="red">*</span></td>
					                </tr>
								</tbody>
							</table>
							
						</td>
					</tr>
				</tbody>
			</table>
			<div align="center">
			   <input class="input_button_3" name="" type="button" onclick="saveEditDict()" value="保存">&nbsp;&nbsp;
	           <input class="input_button_3" name="" type="button" onclick="closeCurrentDIV('editDictDiv')" value="取消">
			</div>
	</div>
				            
				            
			  				 <div id="schoolConfigPageDiv"  class="page"></div>
						</div>
					</td>
				</tr>
			</tbody>
		</table>
		
		<!--选择出单机构 DIV 默认隐藏-->
		<div id="deptDiv" style="display:none;width:80%;">
			<div class="table_title_div">
				<table class="table_title" style='width:100%;height: 20px;'>
					<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('deptDiv')"/></td>
					</tr>
				</table>
			</div>
			<table class="table_02" id="table" style="height:180px;" align="center">
				<tr>
					<td>
						<table class="search_table">
							<tr height="30px">
								<td colspan="3" style="text-align:center">
								 出单机构代码：<input name="txt3"  id="deptCode"  type="text" class="input_text" value="" >&nbsp;&nbsp;
								 出单机构名称：<input name="txt3" id="deptCname"  type="text" class="input_text" value="">
									       <input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryCoreDept(1)"/>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table id="deptTable"  class="content_table_1">
							<thead>
								<tr class="f1">
				                  <th style="width:5%">选择</th>
				                  <th style="width:40%">出单机构代码</th>
				                  <th style="width:55%">出单机构名称</th>
				              	</tr>
							</thead>
							<tbody>
							</tbody>
						</table>
						<div id="deptPageDIV"  class="page"></div>
					</td>
				</tr>
			</table>
			<div align="center" >
			  <input type="button" id="saveRoleBtn" value="确定" onclick="chooseDept()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
			  <input type="button" value="取消" onclick="closeCurrentDIV('deptDiv')" class="input_button_3"/>
			</div>
		</div>
		
		
		
		<div id="Loading" style="display:none" align="center">
			<img src="./images/loading.gif" />
		</div>
		
	<!-- 结束 -->
</body>
</html>